//
//  IndicatorViewController.swift
//  swift各类控件集锦
//
//  Created by iosdev1 on 2016/12/23.
//  Copyright © 2016年 zyy. All rights reserved.
//

import UIKit

class IndicatorViewController: ZyBaseViewController {
    var viewForm:UIView? = nil
    var indicator:UIActivityIndicatorView? = nil
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        self.activityIndicatorStopViewUI()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        let btn:UIButton = UIButton.init(frame: CGRect(x:10, y:10, width:60, height:30))
        self.view.addSubview(btn)
//        btn.titleLabel?.text = "停止"
        btn.setTitle("停止", for: UIControlState.normal)
        btn.backgroundColor = UIColor.white
        btn.setTitleColor(UIColor.black, for: UIControlState.normal)
        btn.addTarget(self, action: #selector(self.activityIndicatorStopViewUI), for: UIControlEvents.touchUpInside)
        self.activityIndicatorStartViewUI()
    }

    func activityIndicatorStartViewUI()  {
        let window:UIWindow! = UIApplication.shared.keyWindow!
        viewForm = UIView.init(frame: CGRect(x:(WIDTH_SCREEN - 100)/2, y:(HEIGHT_SCREEN - 100)/2, width:100, height:100))
        window.addSubview(viewForm!)
        viewForm?.backgroundColor = UIColor.brown
        
        let lblIndicator:UILabel = zyUIlblInitWith(title: "加载中", font: 17, color: UIColor.white, bgColor: UIColor.black)
        lblIndicator.frame = CGRect(x:0, y:60, width:100, height:20)
        viewForm?.addSubview(lblIndicator)
        lblIndicator.textAlignment = NSTextAlignment.center
        
        indicator = UIActivityIndicatorView.init(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
        indicator?.center = CGPoint(x:50, y:30)
        viewForm?.addSubview(indicator!)
        indicator?.color = UIColor.blue
        indicator?.startAnimating()
    }
    
    func activityIndicatorStopViewUI()  {
        indicator?.stopAnimating()
        indicator?.hidesWhenStopped = true
        viewForm?.removeFromSuperview()
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
